package com.example.zhaojianxu.signin.securities.sell

import android.app.Activity
import android.graphics.Color
import android.os.Bundle
import android.support.v7.widget.RecyclerView
import android.view.View
import com.example.zhaojianxu.signin.securities.http.SellEntity
import com.example.zhaojianxu.signin.securities.view.NumberDialogFragment
import com.example.zhaojianxu.signin.securities.view.SellDialogFragment
import kotlinx.android.synthetic.main.securities_item_sell.view.*

/**
 * create by @zhaojianxu on 2019/2/17
 */
class SellViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    fun setData(date: SellEntity) {
        itemView.item_sell_buy.text = "抛售"
        itemView.item_sell_buy.setTextColor(Color.RED)
        itemView.item_sell_buy.setOnClickListener {
            val fragment = SellDialogFragment()
            val bundle = Bundle()
            bundle.putInt("bid",date.bid)
            bundle.putInt("sid",date.sid)
            fragment.arguments = bundle
            fragment.show((itemView.context as? Activity)?.fragmentManager, "")
        }

        itemView.item_sell_name.text = date.buy?.name
        itemView.item_sell_number.text = date.number.toString()
        itemView.item_sell_price.text = date.buy?.price
        if (date.buy?.flag == true) {
            itemView.item_sell_up.text = "up"
            itemView.item_sell_up.setTextColor(Color.RED)
        } else {
            itemView.item_sell_up.text = "down"
            itemView.item_sell_up.setTextColor(Color.GREEN)
        }
    }

}